<?php
session_start();

include('./../config/db_settings.php');
include('./../pms/pms_inc.php');
include('bookmarks_inc.php');

$user = $_SESSION[$settings['session_prefix'].'user_id'];
$user_name = $_SESSION[$settings['session_prefix'].'user_name'];

?>
<html>
<head>
<title>Bookmark Center</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css"
	href="../templates/<? echo $settings['template'] ?>/style_lp.css"
	media="all" />
<script src="../js/google.js" type="text/javascript"></script>
<script src="../js/textLength.js" type="text/javascript"></script>
<script src="../js/javascripts.js" type="text/javascript"></script>

<script type="text/javascript">
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function isUnsignedInteger(s) {
	  return (s.toString().search(/^[0-9]+$/) == 0);
	}


	function checkForm()
	 {
		var id = document.forms['postingform'].elements['post_id'].value.trim();
		var note = document.forms['postingform'].elements['text'].value.trim();
		var isFull = document.forms['postingform'].elements['isFull'].value.trim();

		if(isFull.length > 0){
			alert("Sorry, your bookmark centre is full. If you have deleted some bookmarks, please refresh this page.");
			return false;
		}
		
		if(id.length == 0 && note.length == 0)
		{
			alert("Post # and note can not be both blank.");
			document.forms['postingform'].elements['id'].focus();
			return false;
		}

		if(id.length > 0)
		{
			if(!isUnsignedInteger(id))
			{
				alert("Post # has to be valid or blank.");
				document.forms['postingform'].elements['id'].focus();
				return false;
			}
		}
	  	return true;
	 }
</script>
</head>
<?
//Are they logged in or not?
if(!$user)
    {
    echo "<br><p>You aren't logged in. Please log in first.</p><br>";
    }
    
else
{
	//Get your bookmark count
	//Find the percentage that your inbox is full
	$sql = mysql_query ("SELECT count(*) bm_count FROM ".$db_settings['bookmarks_table']." WHERE user_id='$user'");
	$row = mysql_fetch_array ($sql);
	$bm_count = $row['bm_count'];
	
	$percent = $bm_count/$bookmark_limit;
	$percent = $percent * '100';

?>

<body>
<br>
<center><b><a href="bookmarks.php" target="htkou_bm_center">Bookmark Centre</a></b><br />
<b><? echo "$bm_count"." of "."$bookmark_limit"." Total  |  "."$percent"."% full"; ?></b>
</center>
<div class="content">
<FORM name="f1" METHOD='post' Action='processBookmark.php' id="postingform"
	accept-charset="UTF-8">
		<center>
		<TABLE BORDER=0 cellspacing=1 cellpadding=5 width=500 class="table">

		<TR valign=top >
			<TD>
				<br>
				<span class=title><b>Add a bookmark</b></span>
			</TD>
		</TR>
		<TR>
			<TD align=left>
				<font color=blue>UserID: <? echo $user_name; ?></font>
			</TD>
		</tr>
			<TR valign=top >
				<TD>
					You can bookmark a post with a note, or you can just store a note without a post number.
				</TD>
			</TR>

			<TR valign=top >
				<TD>
					Post #:
					<input type="text" name="post_id" size=12 maxlength=20 value="">
				</TD>
			</TR>
			<TR valign=top >
				<TD>
					Note:
					<textarea name="text" type="text" id="text" value="" cols="70" rows="12" length="1500" ></textarea>
				</TD>
			</TR>
			<TR valign=top >
				<TD>
					<span class="xsmall">Note's max length is 1500 characters. You have <font color="red"><span
			id="textsize"></span></font>&nbsp;characters left.</span>
				</TD>
			</TR>
			<TR>
				<TD><input type="hidden" name="isFull" id="isFull" value='<?php if($bm_count>=$bookmark_limit) echo "1"?>'>
					<INPUT TYPE='submit' value='Submit' onclick="return checkForm();">
				</TD>
			</TR>
			
		</TABLE>
		</center>
		</FORM>
</div>
<script type="text/javascript">
	document.getElementById("textsize").innerHTML = 1500 - document.getElementById("text").value.len();
</script>
<?
	}
?>
</body>
</html>